﻿@model BackEnd.Models.PriceModel
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
    
input, textarea {
    width:180px;
}
</style>
<script>
    $(document).ready(function () {
        //khoi tao calendar
        Calendar.setup({
            inputField: "AuctionTime",
            button: "f_btn1",
            align: "Tr",
            ifFormat: "%Y/%m/%d %H:%M"
        });
        $("#divDialogAuctionHouse").dialog({
            autoOpen: false,
            modal: true,
            height: 480,
            width: 590,
            resizable: false,
            open: function (event, ui) {
                $("#divDialogAuctionHouse").dialog("option", "position", "center");
            }
        });
        ViewAuctionHouse(1);
        $("#divDialogAuctionHouseSublocation").dialog({
            autoOpen: false,
            modal: true,
            height: 480,
            width: 590,
            resizable: false,
            open: function (event, ui) {
                $("#divDialogAuctionHouseSublocation").dialog("option", "position", "center");
            }
        });
        ViewAuctionHouseSublocation(1);
        $("#divDialogCurrency").dialog({
            autoOpen: false,
            modal: true,
            height: 480,
            width: 590,
            resizable: false,
            open: function (event, ui) {
                $("#divDialogCurrency").dialog("option", "position", "center");
            }
        });
        ViewCurrency(1);
        $("#divDialogItemType").dialog({
            autoOpen: false,
            modal: true,
            height: 480,
            width: 590,
            resizable: false,
            open: function (event, ui) {
                $("#divDialogItemType").dialog("option", "position", "center");
            }
        });
        ViewItemType(1);
        
    });   

    function RemoveFileUpload(spanId, fileName) {
        $("#" + spanId).remove();
        $("#Image").val($("#Image").val().replace(fileName + ';', ''));
    }

    var TotalPageAuctionHouse = 0;
    var TotalPageAuctionHouseSublocation = 0;
    var TotalPageCurrency = 0;
    var TotalPageItemType = 0;
    var PageSize=10;
    function ViewAuctionHouse(PageIndex) {
        $.ajax({
            url: '/AuctionHouse/Search',
            type: 'POST',
            data: {
                name: $('#iptAuctionHouseName').val(),
                pageIndex: PageIndex,
                pageSize: PageSize
            },
            success: function (data) {
                var str = '<table id="rounded-corner" style="width:554px"><thead><tr>';
                str += '<th class="rounded-company" scope="col">Id</th>';
                str += '<th class="rounded" scope="col">Name</th>';
                str += '<th class="rounded" scope="col">Link</th>';
                str += '<th class="rounded-q4" scope="col"></th>';
                str += '</tr>';
                TotalPageAuctionHouse = Math.ceil(data.TotalRecord / PageSize);
                if (TotalPageAuctionHouse > 1) {
                    $("#divPagerAuctionHouse").show();
                }else {
                    $("#divPagerAuctionHouse").hide();
                }                
                $.each(data.ListItem, function (i, item) {                    
                    str += "<tr>";                    
                    str += "<td style='text-align:center'>"+item.Id+"</td>";
                    str += "<td style='text-align:left'>" + item.Name + "</td>";                    
                    str += "<td style='text-align:left'>" + item.Link + "</td>";
                    str += "<td style='text-align:left'><a href=javascript:SelectAuctionHouse(" + item.Id + ",'" + encodeURIComponent(item.Name) + "') >Select</a></td>";
                    str += "</tr>";
                });          
                str += '</thead></table>';
                $("#divContentAuctionHouse").html(str);
                $("#divPagerAuctionHouse").pager({ pagenumber: PageIndex, pagecount: TotalPageAuctionHouse, buttonClickCallback: ViewAuctionHouse });
            }
        });
    }

    function ViewAuctionHouseSublocation(PageIndex) {
        $.ajax({
            url: '/AuctionHouseSublocation/Search',
            type: 'POST',
            data: {
                name: $('#iptAuctionHouseSublocationName').val(),
                auctionHouseID: -1,
                pageIndex: PageIndex,
                pageSize: PageSize
            },
            success: function (data) {
                var str = '<table id="rounded-corner" style="width:554px"><thead><tr>';
                str += '<th class="rounded-company" scope="col">Id</th>';
                str += '<th class="rounded" scope="col">Auction House Sublocation Name</th>';
                str += '<th class="rounded" scope="col">Auction House Name</th>';
                str += '<th class="rounded-q4" scope="col"></th>';
                str += '</tr>';
                TotalPageAuctionHouseSublocation = Math.ceil(data.TotalRecord / PageSize);
                if (TotalPageAuctionHouseSublocation > 1) {
                    $("#divPagerAuctionHouseSublocation").show();
                } else {
                    $("#divPagerAuctionHouseSublocation").hide();
                }
                $.each(data.ListItem, function (i, item) {
                    str += "<tr>";
                    str += "<td style='text-align:center'>" + item.Id + "</td>";
                    str += "<td style='text-align:left'>" + item.AuctionHouseSublocationName + "</td>";
                    str += "<td style='text-align:left'>" + item.AuctionHouseName + "</td>";
                    str += "<td style='text-align:left'><a href=javascript:SelectAuctionHouseSublocation(" + item.Id + ",'" + encodeURIComponent(item.AuctionHouseSublocationName) + "') >Select</a></td>";
                    str += "</tr>";
                });
                str += '</thead></table>';
                $("#divContentAuctionHouseSublocation").html(str);
                $("#divPagerAuctionHouseSublocation").pager({ pagenumber: PageIndex, pagecount: TotalPageAuctionHouseSublocation, buttonClickCallback: ViewAuctionHouseSublocation });
            }
        });
    }

    function ViewCurrency(PageIndex) {
        $.ajax({
            url: '/Currency/Search',
            type: 'POST',
            data: {
                name: $('#iptCurrency').val(),
                pageIndex: PageIndex,
                pageSize: PageSize
            },
            success: function (data) {
                var str = '<table id="rounded-corner" style="width:554px"><thead><tr>';
                str += '<th class="rounded-company" scope="col">Id</th>';
                str += '<th class="rounded" scope="col">Currency</th>';
                str += '<th class="rounded" scope="col">Country</th>';
                str += '<th class="rounded-q4" scope="col"></th>';
                str += '</tr>';
                TotalPageCurrency = Math.ceil(data.TotalRecord / PageSize);
                if (TotalPageCurrency > 1) {
                    $("#divPagerCurrency").show();
                } else {
                    $("#divPagerCurrency").hide();
                }
                $.each(data.ListItem, function (i, item) {
                    str += "<tr>";
                    str += "<td style='text-align:center'>" + item.Id + "</td>";
                    str += "<td style='text-align:left'>" + item.Currency + "</td>";
                    str += "<td style='text-align:left'>" + item.Country + "</td>";
                    str += "<td style='text-align:left'><a href=javascript:SelectCurrency(" + item.Id + ",'" + encodeURIComponent(item.Currency) + "') >Select</a></td>";
                    str += "</tr>";
                });
                str += '</thead></table>';
                $("#divContentCurrency").html(str);
                $("#divPagerCurrency").pager({ pagenumber: PageIndex, pagecount: TotalPageCurrency, buttonClickCallback: ViewCurrency });
            }
        });
    }

    function ViewItemType(PageIndex) {
        $.ajax({
            url: '/ItemType/Search',
            type: 'POST',
            data: {
                name: $('#iptItemType').val(),
                pageIndex: PageIndex,
                pageSize: PageSize
            },
            success: function (data) {
                var str = '<table id="rounded-corner" style="width:554px"><thead><tr>';
                str += '<th class="rounded-company" scope="col">Id</th>';
                str += '<th class="rounded" scope="col">Name</th>';
                str += '<th class="rounded-q4" scope="col"></th>';
                str += '</tr>';
                TotalPageItemType = Math.ceil(data.TotalRecord / PageSize);
                if (TotalPageItemType > 1) {
                    $("#divPagerItemType").show();
                } else {
                    $("#divPagerItemType").hide();
                }
                $.each(data.ListItem, function (i, item) {
                    str += "<tr>";
                    str += "<td style='text-align:center'>" + item.Id + "</td>";
                    str += "<td style='text-align:left'>" + item.Name + "</td>";                    
                    str += "<td style='text-align:left'><a href=javascript:SelectItemType(" + item.Id + ",'" + encodeURIComponent(item.Name) + "') >Select</a></td>";
                    str += "</tr>";
                });
                str += '</thead></table>';
                $("#divContentItemType").html(str);
                $("#divPagerItemType").pager({ pagenumber: PageIndex, pagecount: TotalPageItemType, buttonClickCallback: ViewItemType });
            }
        });
    }

    function SelectAuctionHouse(id, name)
    {
        $('#AuctionHouse').val(id);
        $('#AuctionHouseName').val(name);
        HidePopupAuctionHouse();
    }

    function SelectAuctionHouseSublocation(id, name) {
        $('#AuctionHouseSublocation').val(id);
        $('#AuctionHouseSublocationName').val(name);
        HidePopupAuctionHouseSublocation();
    }

    function SelectCurrency(id, name) {
        if ($("#iphTypeCurrency").val() == '1') {
            $('#EstimatedCurrency').val(id);
            $('#EstimatedCurrencyName').val(name);
        }
        else {
            $('#PriceCurrency').val(id);
            $('#PriceCurrencyName').val(name);
        }
        HidePopupCurrency();
    }

    function SelectItemType(id, name) {
        $('#ItemType').val(id);
        $('#ItemTypeName').val(name);
        HidePopupItemType();
    }

    function ShowPopupAuctionHouse() {        
        $("#divDialogAuctionHouse").dialog("open");
    }

    function HidePopupAuctionHouse() {
        $("#divDialogAuctionHouse").dialog("close");
    }

    function ShowPopupAuctionHouseSublocation() {
        $("#divDialogAuctionHouseSublocation").dialog("open");
    }

    function HidePopupAuctionHouseSublocation() {
        $("#divDialogAuctionHouseSublocation").dialog("close");
    }

    function ShowPopupCurrency(type)
    {
        $("#iphTypeCurrency").val(type);
        $("#divDialogCurrency").dialog("open");
    }

    function HidePopupCurrency() {
        $("#divDialogCurrency").dialog("close");
    }

    function ShowPopupItemType() {        
        $("#divDialogItemType").dialog("open");
    }

    function HidePopupItemType() {
        $("#divDialogItemType").dialog("close");
    }
</script>
<h2>Create Price</h2>
@using (Html.BeginForm("Create", "Price", FormMethod.Post))
{ 
    <table>
        <tr>
            <td>@Html.LabelFor(m => m.ItemName)</td>
            <td>@Html.TextBoxFor(m => m.ItemName)<br />
                @Html.ValidationMessage("ItemName", new { style="color:#CC0000"})</td>
            <td>@Html.LabelFor(m => m.ItemTypeName)</td>
            <td>
                @Html.TextBoxFor(m => m.ItemTypeName)                
                <a href="javascript:ShowPopupItemType()"><img src="/Content/Images/search.png" /></a><br />
                @Html.ValidationMessage("ItemType", new { style="color:#CC0000"}) 
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.ItemTypeDescription)</td>
            <td>@Html.TextBoxFor(m => m.ItemTypeDescription)</td>
            <td>@Html.LabelFor(m => m.Height)</td>
            <td>@Html.TextBoxFor(m => m.Height)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Width)</td>
            <td>@Html.TextBoxFor(m => m.Width)</td>
            <td>@Html.LabelFor(m => m.Depth)</td>
            <td>@Html.TextBoxFor(m => m.Depth)</td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Measurement)</td>
            <td>@Html.TextBoxFor(m => m.Measurement)</td>            
            <td>@Html.LabelFor(m => m.Impression)</td>
            <td>
                @Html.TextBoxFor(m => m.Impression)                
            </td>
        </tr>
        <tr>
            <td colspan="4">
                @Html.LabelFor(m => m.Stamped, new { style="float:left;" }) @Html.CheckBoxFor(m => m.Stamped, new { style="float:left;margin-left: 10px;" })                    
                @Html.LabelFor(m => m.Inscribed, new { style="float:left;margin-left: 10px;" }) @Html.CheckBoxFor(m => m.Inscribed, new { style="float:left;margin-left: 10px;" })
                @Html.LabelFor(m => m.Signed, new { style="float:left;margin-left: 10px;" }) @Html.CheckBoxFor(m => m.Signed, new { style="float:left;margin-left: 10px;" })  
            </td>                 
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Dating)</td>
            <td>@Html.TextBoxFor(m => m.Dating)</td>
            <td>@Html.LabelFor(m => m.Lotnumber)</td>
            <td>
                @Html.TextBoxFor(m => m.Lotnumber)<br />
                @Html.ValidationMessage("Lotnumber", new { style="color:#CC0000"})
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.AuctionTime)</td>
            <td>
                @Html.TextBoxFor(m => m.AuctionTime)<br />
                @Html.ValidationMessage("AuctionTime", new { style="color:#CC0000"})
            </td>
            <td>@Html.LabelFor(m => m.Auctionnumber)</td>
            <td>
                @Html.TextBoxFor(m => m.Auctionnumber)                
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m=>m.AuctionHouseName)</td>
            <td>
                @Html.TextBoxFor(m => m.AuctionHouseName)                
                <a href="javascript:ShowPopupAuctionHouse()"><img src="/Content/Images/search.png" /></a><br />
                @Html.ValidationMessage("AuctionHouseName", new { style="color:#CC0000"})
            </td>
            <td>@Html.LabelFor(m=>m.AuctionHouseSublocationName)</td>
            <td>
                @Html.TextBoxFor(m => m.AuctionHouseSublocationName)                
                <a href="javascript:ShowPopupAuctionHouseSublocation()"><img src="/Content/Images/search.png" /></a><br />
                @Html.ValidationMessage("AuctionHouseSublocationName", new { style="color:#CC0000"})
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.EstimatedFrom)</td>
            <td>
                @Html.TextBoxFor(m => m.EstimatedFrom)                
            </td>
            <td>@Html.LabelFor(m => m.EstimatedTo)</td>
            <td>
                @Html.TextBoxFor(m => m.EstimatedTo)                
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.EstimatedCurrencyName)</td>
            <td>
                @Html.TextBoxFor(m => m.EstimatedCurrencyName)                   
                <a href="javascript:ShowPopupCurrency(1)"><img src="/Content/Images/search.png" /></a><br /> 
                @Html.ValidationMessage("EstimatedCurrencyName", new { style="color:#CC0000"})            
            </td>
            <td>@Html.LabelFor(m => m.Price)</td>
            <td>
                @Html.TextBoxFor(m => m.Price)                
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.PriceCurrencyName)</td>
            <td>
                @Html.TextBoxFor(m => m.PriceCurrencyName)                
                <a href="javascript:ShowPopupCurrency(2)"><img src="/Content/Images/search.png" /></a><br />
                @Html.ValidationMessage("PriceCurrencyName", new { style="color:#CC0000"})          
            </td>
            <td>@Html.LabelFor(m => m.PriceInUS)</td>
            <td>
                @Html.TextBoxFor(m => m.PriceInUS)                
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Premium)</td>
            <td>
                @Html.CheckBoxFor(m => m.Premium)                
            </td>
            <td>@Html.LabelFor(m => m.Unsold)</td>
            <td>
                @Html.CheckBoxFor(m => m.Unsold)                
            </td>
        </tr>        
        <tr>
            <td>@Html.LabelFor(m => m.Edition)</td>
            <td>
                @Html.TextBoxFor(m => m.Edition)                
            </td>
            <td>@Html.LabelFor(m => m.Foundry)</td>
            <td>
                @Html.TextBoxFor(m => m.Foundry)                
            </td>
        </tr>
        <tr>
            <td>@Html.LabelFor(m => m.Image)</td>
            <td colspan="3">
                <input type="file" id="ipfImage"/>            
                    <script type="text/javascript">
                        $('#ipfImage').uploadify({
                            'script': '/Price/UploadFile',
                            'uploader': '/Scripts/uploadify/uploadify.swf',
                            'buttonImg': '/Scripts/uploadify/btn_select.png',
                            'cancelImg': '/Scripts/uploadify/cancel.png',
                            'folder': '/Price',
                            'width': '51',
                            'height': '23',
                            'fileExt': '*.jpg;*.gif;*.png;',
                            'fileDesc': '*.jpg;*.gif;*.png;',
                            'sizeLimit': '52428800',
                            'queueSizeLimit': 10,
                            'multi': true,
                            'auto': true,
                            'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
                            'onQueueFull': function (event, queueID, fileObj) {
                            },
                            'onSelect': function (event, queueID, fileObj) {
                            },
                            'onError': function (event, queueID, fileObj, obj) {
                            },
                            'onProgress': function (event, queueID, fileObj, obj) {
                            },
                            'onComplete': function (event, queueID, fileObj, response, data) {
                                var json = eval("(" + response + ")");
                                if (json.errorCode == 100) {
                                    $('#Image').val($('#Image').val() + json.fileName + ";");
                                    var spanId = json.fileName.replace(/\./gi, "_");
                                    var str = "<span id=" + spanId + ">" + json.fileName + " (<a href=javascript:RemoveFileUpload('" + spanId + "','" + json.fileName + "')>Xóa</a>)<br/></span>";
                                    $("#fileQueue").html($("#fileQueue").html() + str);
                                } else {
                                }
                            },
                            'onAllComplete': function () {
                            }
                        });
                </script>
                <div id="fileQueue">               
                </div>
            </td>
        </tr>
        <tr>
            <td></td>
            <td colspan="3">
                @Html.HiddenFor(m=>m.Image)
                @Html.HiddenFor(m=>m.ArtistId)
                @Html.HiddenFor(m=>m.AuctionHouse)
                @Html.HiddenFor(m=>m.AuctionHouseSublocation)
                @Html.HiddenFor(m=>m.EstimatedCurrency)
                @Html.HiddenFor(m=>m.PriceCurrency)
                @Html.HiddenFor(m=>m.ItemType)
                <input type="hidden" id="iphTypeCurrency" />
                <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="submit" class="NFButton NFh" value="Create"/><img class="NFButtonRight NFh" src="/Content/Img/0.png">
                @Html.ActionLink("Back", "ListPriceByArtist", "Price", new { artistId = Model.ArtistId}, null)
            </td>
        </tr>
    </table>
<div id="divDialogAuctionHouse" class="div_dialog" style="display: none;z-index:100000" title="Select Auction House"> 
    <div class="clear">
    </div>
    <div style="width: 100%;"> 
        <div style="width: 100%;">
            <input type="text" id="iptAuctionHouseName" />
            <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" id="ipbSearchAuctionHouse" value="Search" onclick="ViewAuctionHouse(1)" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
            <div id="divContentAuctionHouse"></div>
            <div id="divPagerAuctionHouse" class="pagination" style="width:554px"></div>
        </div>
    </div>
    <div class=" pad15 clear">
    </div> 
</div>
<div id="divDialogAuctionHouseSublocation" class="div_dialog" style="display: none;z-index:100000" title="Select Auction House Sublocation"> 
    <div class="clear">
    </div>
    <div style="width: 100%;"> 
        <div style="width: 100%;">
            <input type="text" id="iptAuctionHouseSublocationName" />
            <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" id="ipbSearchAuctionHouseSublocation" value="Search" onclick="ViewAuctionHouseSublocation(1)" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
            <div id="divContentAuctionHouseSublocation"></div>
            <div id="divPagerAuctionHouseSublocation" class="pagination" style="width:554px"></div>
        </div>
    </div>
    <div class=" pad15 clear">
    </div> 
</div>
<div id="divDialogCurrency" class="div_dialog" style="display: none;z-index:100000" title="Select Currency"> 
    <div class="clear">
    </div>
    <div style="width: 100%;"> 
        <div style="width: 100%;">
            <input type="text" id="iptCurrency" />
            <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" id="ipbSearchCurrency" value="Search" onclick="ViewCurrency(1)" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
            <div id="divContentCurrency"></div>
            <div id="divPagerCurrency" class="pagination" style="width:554px"></div>
        </div>
    </div>
    <div class=" pad15 clear">
    </div> 
</div>
<div id="divDialogItemType" class="div_dialog" style="display: none;z-index:100000" title="Select ItemType"> 
    <div class="clear">
    </div>
    <div style="width: 100%;"> 
        <div style="width: 100%;">
            <input type="text" id="iptItemType" />
            <img class="NFButtonLeft NFh" src="/Content/Img/0.png"><input type="button" class="NFButton NFh" id="ipbSearchItemType" value="Search" onclick="ViewItemType(1)" /><img class="NFButtonRight NFh" src="/Content/Img/0.png">
            <div id="divContentItemType"></div>
            <div id="divPagerItemType" class="pagination" style="width:554px"></div>
        </div>
    </div>
    <div class=" pad15 clear">
    </div> 
</div>
}
